#ifndef __AGATTACHMENTCONTROL_H__
#define __AGATTACHMENTCONTROL_H__

#pragma once

#include "IAnimationStateNode.h"

class CAGAttachmentControl;

class CAGAttachmentControlFactory : public IAnimationStateNodeFactory
{
	friend class CAGAttachmentControl;

public:
	// IAnimationStateNodeFactory
	virtual bool Init( const XmlNodeRef& node, IAnimationGraphPtr );
	virtual void Release();
	virtual IAnimationStateNode * Create();
	virtual const char * GetCategory();
	virtual const char * GetName();
	virtual const Params * GetParameters();
	virtual void SerializeAsFile(bool reading, AG_FILE *file);

	virtual bool IsLessThan( IAnimationStateNodeFactory * pFactory )
	{
		AG_LT_BEGIN(CAGAttachmentControlFactory);
			AG_LT_ELEM(m_attachment);
			AG_LT_ELEM(m_controlType);
			AG_LT_ELEM(m_animationName);
			AG_LT_ELEM(m_animationLoop);
			AG_LT_ELEM(m_animationLayer);
			AG_LT_ELEM(m_stopAnimLayer);
			AG_LT_ELEM(m_stopAnimTime);
		AG_LT_END();
	}

	virtual void GetMemoryUsage(ICrySizer * s) const
	{
		s->Add(*this);
		s->Add(m_attachment);
		s->Add(m_controlType);
		s->Add(m_animationName);
		s->Add(m_animationLoop);
		s->Add(m_animationLayer);
		s->Add(m_stopAnimLayer);
		s->Add(m_stopAnimTime);
	}
	// ~IAnimationStateNodeFactory

private:
  ILINE const string& GetAttachmentName() const { return m_attachment; }
	ILINE const string& GetAnimationName() const { return m_animationName; }
	ILINE int GetLayerNumber() const { return m_animationLayer; }
	ILINE bool GetLoopingAnim() const { return m_animationLoop; }


private:

	enum EAGAttachmentControl_Type 
	{
		ePlayAnimation = 0,
		eStopAnimation,
		eShowAttachment,
		eHideAttachment,
	};

  string	m_attachment;  
	int			m_controlType;


  string	m_animationName;    
  bool		m_animationLoop;
  int			m_animationLayer;

	int			m_stopAnimLayer;
	float		m_stopAnimTime;
};

class CAGAttachmentControl : public IAnimationStateNode
{
public:
	CAGAttachmentControl(CAGAttachmentControlFactory* pFactory);
	
	// IAnimationStateNode
	virtual void EnterState( SAnimationStateData& data, bool dueToRollback );
	virtual EHasEnteredState HasEnteredState( SAnimationStateData& data ) { return eHES_Instant; }
	virtual bool CanLeaveState( SAnimationStateData& data );
	virtual void LeaveState( SAnimationStateData& data );
	virtual void EnteredState( SAnimationStateData& data );
	virtual void LeftState( SAnimationStateData& data, bool wasEntered );
	virtual void Update( SAnimationStateData& data );
	virtual void GetCompletionTimes( SAnimationStateData& data, CTimeValue start, CTimeValue& hard, CTimeValue& sticky );
	virtual IAnimationStateNodeFactory * GetFactory() { return m_pFactory; }
	virtual void DebugDraw( SAnimationStateData& data, IRenderer * pRenderer, int x, int& y, int yIncrement ) {}
	// ~IAnimationStateNode

	virtual void GetMemoryUsage(ICrySizer * s) const
	{
		s->Add(*this);
	}

private:
	void StartAttachmentAnimation( IAttachment* pA, bool doLog );
	void StopAttachmentAnimation( IAttachment* pA, bool doLog );
	CAGAttachmentControlFactory* m_pFactory;

};

#endif // __AGATTACHMENTCONTROL_H__
